package cn.sc.summer.mybatis.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.math.BigDecimal;
import java.sql.Time;
import java.sql.Timestamp;
import java.util.Date;

/**
 * 枚举类型：postgresql基础类型与java类型对照表
 *
 * @author a-xin
 * @date 2024/8/26 15:06
 */
@Getter
@AllArgsConstructor
public enum PostgreSqlJavaTypeEnum {

    INT_2("int2", Integer.class, 1, -1),
    INT_4("int4", Integer.class, 2, -1),

    INT_8("int8", Long.class, 1, -1),

    CAR_CHAR("varchar", String.class, 1, 255),
    CHAR("char", String.class, 2, 255),
    TEXT("text", String.class, 3, -1),

    NUMERIC("numeric", BigDecimal.class, 1, 6),

    FLOAT_4("float4", Float.class, 1, 2),

    FLOAT_8("float8", Double.class, 1, 2),
    MONEY("money", Double.class, 2, 2),

    BIT("bit", Boolean.class, 1, -1),
    BOOL("bool", Boolean.class, 2, -1),

    TIME("time", Time.class, 1, -1),
    TIME_STAMP("timestamp", Timestamp.class, 1, -1),
    DATE("timestamp", Date.class, 1, -1),
    ;

    /**
     * mysql类型
     */
    private final String dataSourceType;

    /**
     * java对应类型
     */
    private final Class<?> javaType;

    /**
     * 优先级，同类型优先级高的优先选择
     */
    private final Integer priority;

    /**
     * 字段默认长度，若为-1则不用添加长度属性
     */
    private final Integer defaultLength;

}
